<template>
	<view class="safe-area-inset-bottom">
		<!-- 企业添加 -->
				<!-- 搜索框 -->
				<view class="swip_header">
				<view class="slot-box">
					<view style="width: 100%;">
						<uni-search-bar v-model="queryParams.name" type="text" @confirm="handleQuery" @input="handleQuery" placeholder="请输入企业名称" />
					</view>
				</view>
				</view>
				
			<view class="scroll_view" v-if="companyList.length !== 0">
				<view @click="selectChange(item,index)" v-for="(item, index) in companyList" :key="index" class="table_view">
					<view>
						<i class="iconfont grayIcon" style="margin:0 10rpx 0 0;font-size: 30rpx;"
							v-if="item.isCertify == 0">&#xe681;</i>
						<i class="iconfont greenIcon" style="margin:0 10rpx 0 0;font-size: 27rpx;"
							v-else>&#xe681;</i>
					{{item.name}}</view>
						<span style="color: #00a660;">使用</span>
				</view>
			</view>

			<!-- 暂无数据 -->
			<luanqingEmpty :show="true" text="没有更多数据啦" v-else />
	</view>
</template>

<script>
	import luanqingEmpty from '@/components/luanqing-empty/luanqing-empty';
	import {getCustomerCompany} from "@/api/ec/work/customer/customerCompany";
	import {listCustomerCompany} from "@/api/ec/work/customer/customerCompany";
	import {listCustomerCompanyPerson} from "@/api/ec/person/customer/customerCompany";
	export default {
		components: {
			luanqingEmpty
		},
		name: "selectCompany",
		data() {
			return {
				companyList: [],
				// 查询参数
				queryParams: {
				  pageNum: 1,
				  pageSize: 10,
				  name: undefined,
				},
				index:0,
				companyCopy:false,
			};
		},
		onLoad(option) {
			this.index = option.index
			this.companyCopy = option.companyCopy
			this.getList()
		},
		methods: {
			/** 查询企业信息列表 */
			getList() {
			  if(this.$store.getters.staffInfo.companyId !== 0){
			    listCustomerCompany(this.queryParams).then(response => {
			      this.companyList = response.rows;
			    });
			  } else {
			    listCustomerCompanyPerson(this.queryParams).then(response => {
			      this.companyList = response.rows;
			    });
			  }
			},    
			/**搜索*/
			handleQuery() {
				this.getList()
			},
			/** 选择使用联系人 */
			selectChange(item,index) {
				getCustomerCompany(item.id).then(response =>{
				  let data = response.data
				  if(this.companyCopy){
					  let ruleForm = {id:0,sendName:null,sendMobile:null,senderType:0,sendCompany:data.name,customerCompanyId:data.id,index:this.index}
					  uni.$emit('copyCompanyData',ruleForm)
				  }else{
					  let ruleForm = {signCompany:data.name,signerName:'',signerMobile:'',customerCompanyId:data.id,index:this.index}
					  uni.$emit('companyData',ruleForm)
				  }
				  uni.navigateBack(1)
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	page {
			background: $uni-bg-color;
		}
		.scroll_view{
			position: absolute;
			top: 110rpx;
			height:80%;
			width: 100%;
			overflow-y: scroll;
		}
	.table_view{
		height: 100rpx;
		line-height: 100rpx;
		border-bottom: 1rpx solid #ebeef5;
		padding: 0 20rpx 0 0;
		display: flex;
		justify-content: space-between;
		margin:0 20rpx;
	}	
</style>
